#!/bin/bash

#计算日期差距

#输入生日
read -p "Input your birthday(1980-01-01):" bday

#测试是否正确
bday_d=`echo $bday | grep '[0-9]\{8\}'`
if [ "$bday_d" == "" ]; then
    echo "必须输入日期"
    exit 1
fi

#开始计算
bday=`date --date="$bday" +%s`
today=`date +%s`
#echo $bday
#echo $today
diffdays=$(($today-$bday)) 
diffdays_d=$(($diffdays/60/60/24))
#echo $diffdays
if [ "$diffdays_d" -gt "0" ]; then
    echo "You had lived:" $diffdays_d "days"
else
    echo "abc"
fi
